package cn.edu.masu._20241009;

/**
 * @Description 不规则数组定义杨辉三角前10行
 * @Author xuezipeng
 * @Date 2024-10-09 15:58
 */
public class HomeWork20241009 {

    private static final int COLUMN_COUNT = 10;
    private static final int ROW_COUNT = 10;
    private static final String CONTENT_SEPARATOR = " ";

    enum Colors{
        RED("\033[033;31m" + "%d" + "\033[0m");

        private final String value;

        Colors(String value){
            this.value = value;
        }
    }

    public static void main(String[] args) {

        int[][] resultArray = new int[ROW_COUNT][COLUMN_COUNT];

        for (int row = 0; row < ROW_COUNT; row++) {

            for (int column = 0; column <= row; column++) {

                resultArray[row][column] = column == 0 ? 1 : resultArray[row - 1][column - 1] + resultArray[row - 1][column];

                int currentVal = resultArray[row][column];

                System.out.print(
                        (currentVal == 1 ? String.format(Colors.RED.value, currentVal) : currentVal)
                        + CONTENT_SEPARATOR
                );

            }

            System.out.println();

        }

    }

}
